package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.dto.QueryStudentDto;
import com.itheima.pojo.Student;
import com.itheima.vo.StudentVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface StudentMapper {

    /**
     * 添加学生
     */
    void insert(Student student);

    /**
     * 动态条件查询
     */
    Page<StudentVo> list(QueryStudentDto dto);

    /**
     * 根据ID查询学生信息
     */
    @Select("select * from student where id = #{id}")
    Student getById(Integer id);

    /**
     * 修改学生信息
     */
    void update(Student student);

    /**
     * 违纪处理
     */
    void updateViolation(Integer id, Integer score);

    @Select("select count(*) from student where clazz_id = #{id}")
    Integer countByClazzId(Integer id);

    /**
     * 根据id删除
     *
     * @param id
     */
    @Delete("delete from student where id=#{id}")
    void deleteById(Integer id);

    /**
     * 统计学员学历
     */
    @MapKey("name")
    List<Map> getStudentDegreeData();

    /**
     * 统计班级人数
     */
    @Select("select c.name cname , count(s.id) scount from clazz c  left join student s on s.clazz_id = c.id group by c.name order by count(s.id) desc ")
    List<Map> getStudentCount();

}
